package jmind.core.support;

import org.python.core.PyFunction;
import org.python.core.PyInteger;
import org.python.core.PyObject;
import org.python.util.PythonInterpreter;

/**
 * Created by weibo.xwb on 2017/12/26.
 */
public class PythonUtil {
    public static PyObject call(String filename,String method,PyObject... args){
        PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.execfile(filename);
        PyFunction func = (PyFunction)interpreter.get(method,PyFunction.class);
        PyObject pyobj = func.__call__(args);
       return pyobj;
    }

    public static void main(String args[])
    {
        System.setProperty("python.import.site","false");
        PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.exec("days=('mod','Tue','Wed','Thu','Fri','Sat','Sun'); ");
        interpreter.exec("print days[1];");
        PyObject adder = call("d:/data/my_utils.py", "adder", new PyInteger(121), new PyInteger(1));
        System.out.println(adder.toString());

    }//main

}
